import { observable, action } from 'mobx'
import axios from 'axios'
import notificationWithIcon from "../../../common/notificationWithIcon";
import modalDisplay from "../../../common/informModal";

class CorporationInfoStore {
    @observable corporationInfo={}
    @observable validateStatus=""
    // 0 未认证
    // 1 审核中
    // 2 认证成功
    // 3 需要进行修改操作
    actions = {
        getStatus: action(()=>{
            axios.get('/api/user/auth/status/company')
                .then((response)=> {
                    if(response.data.status.code===1021){
                        this.validateStatus="0"
                    }
                    else if(response.data.status.code===1022){
                        this.validateStatus="1"
                    }
                    else if(response.data.status.code===1020){
                        this.corporationInfo=response.data.result
                        this.validateStatus="2"
                    }
                    else if(response.data.status.code===1023){
                        this.corporationInfo=response.data.result
                        this.validateStatus="4"
                    }
                })
                .catch(function (error) {
                   console.log(error)
                });
        }),
        launchCorporationInfo: action((corporationInfo,toggle)=>{
            corporationInfo.licensePath=this.corporationInfo.licensePath
            axios.post('/api/user/auth/company',corporationInfo)
                .then((response)=> {
                    if(response.data.status.code===1){
                        toggle(false)
                        modalDisplay('success','成功',"你的认证信息已提交，我们会在24小时内通过",null)
                        this.actions.getStatus()
                    }
                    else{
                        toggle(false)
                        modalDisplay('error',response.data.status.message,"",null)
                    }
                })
                .catch(function (error) {
                    toggle(false)
                    modalDisplay('error','提交失败',error.response,null)
                    console.log(error);
                });
        })
    }
}
export default new CorporationInfoStore()